<template>
  <div class="media-registration">
    <div
      class="page-header"
      :style="bannerImage ? { backgroundImage: `url(${bannerImage})` } : {}"
      :class="{ 'has-bg': !!bannerImage }"
    >
      <div class="container">
        <h1 class="page-title">媒体注册</h1>
        <p class="page-subtitle">为媒体记者提供专业的展会报道服务</p>
      </div>
    </div>
    <!-- 导航菜单 -->
    <div class="nav-menu">
      <div class="container">
        <nav class="about-nav">
          <a
            @click="setActiveTab('exhibition-news')"
            :class="['nav-item', { active: activeTab === 'exhibition-news' }]"
          >
            展会资讯
          </a>
          <a
            @click="setActiveTab('media-reports')"
            :class="['nav-item', { active: activeTab === 'media-reports' }]"
          >
            媒体报道
          </a>
          <a
            @click="setActiveTab('industry-news')"
            :class="['nav-item', { active: activeTab === 'industry-news' }]"
          >
            行业资讯
          </a>
          <a
            @click="setActiveTab('on-site-highlights')"
            :class="[
              'nav-item',
              { active: activeTab === 'on-site-highlights' },
            ]"
          >
            现场集锦
          </a>
          <a
            @click="setActiveTab('cooperative-media')"
            :class="['nav-item', { active: activeTab === 'cooperative-media' }]"
          >
            合作媒体
          </a>
          <a
            @click="setActiveTab('media-registration')"
            :class="[
              'nav-item',
              { active: activeTab === 'media-registration' },
            ]"
          >
            媒体注册
          </a>
        </nav>
      </div>
    </div>

    <div class="container">
      <section class="registration-section">
        <!-- <h2 class="section-title">媒体注册</h2> -->
        <div class="registration-content">
          <div class="registration-info">
            <h3>媒体记者专属服务</h3>
            <p>
              为媒体记者提供专业的展会报道服务，包括新闻素材、采访安排、现场支持等全方位服务。
            </p>
            <div class="media-benefits">
              <div class="benefit-item">
                <el-icon><Document /></el-icon>
                <span>新闻素材</span>
              </div>
              <div class="benefit-item">
                <el-icon><VideoCamera /></el-icon>
                <span>采访安排</span>
              </div>
              <div class="benefit-item">
                <el-icon><Connection /></el-icon>
                <span>现场支持</span>
              </div>
              <div class="benefit-item">
                <el-icon><Star /></el-icon>
                <span>专属服务</span>
              </div>
            </div>
          </div>
          <div class="registration-form">
            <form
              @submit.prevent="submitMediaRegistration"
              class="media-registration-form"
            >
              <div class="form-group">
                <label for="mediaName">媒体机构名称 *</label>
                <input
                  type="text"
                  id="mediaName"
                  v-model="mediaForm.name"
                  required
                />
              </div>
              <div class="form-group">
                <label for="mediaType">媒体类型 *</label>
                <select id="mediaType" v-model="mediaForm.type" required>
                  <option value="">请选择媒体类型</option>
                  <option value="报纸">报纸</option>
                  <option value="杂志">杂志</option>
                  <option value="电视">电视</option>
                  <option value="网络">网络</option>
                  <option value="新媒体">新媒体</option>
                </select>
              </div>
              <div class="form-row">
                <div class="form-group">
                  <label for="reporterName">记者姓名 *</label>
                  <input
                    type="text"
                    id="reporterName"
                    v-model="mediaForm.reporterName"
                    required
                  />
                </div>
                <div class="form-group">
                  <label for="reporterPosition">记者职务 *</label>
                  <input
                    type="text"
                    id="reporterPosition"
                    v-model="mediaForm.reporterPosition"
                    required
                  />
                </div>
              </div>
              <div class="form-group">
                <label for="reporterPhone">联系电话 *</label>
                <input
                  type="tel"
                  id="reporterPhone"
                  v-model="mediaForm.reporterPhone"
                  required
                />
              </div>
              <div class="form-group">
                <label for="reporterEmail">电子邮箱 *</label>
                <input
                  type="email"
                  id="reporterEmail"
                  v-model="mediaForm.reporterEmail"
                  required
                />
              </div>
              <div class="form-group">
                <label for="coveragePlan">报道计划</label>
                <textarea
                  id="coveragePlan"
                  v-model="mediaForm.coveragePlan"
                  rows="4"
                  placeholder="请描述您的报道计划..."
                ></textarea>
              </div>
              <button type="submit" class="submit-btn">提交媒体注册</button>
            </form>
          </div>
        </div>
      </section>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import { ElMessage } from "element-plus";
import {
  Document,
  VideoCamera,
  Connection,
  Star,
} from "@element-plus/icons-vue";
import { mediaApi, subpageApi } from "@/api/user";

export default {
  name: "MediaRegistration",
  setup() {
    const activeTab = ref("media-registration");
    // 页面数据
    const pageData = ref({});
    const bannerImage = ref("");

    // 媒体注册表单数据
    const mediaForm = ref({
      name: "",
      type: "",
      reporterName: "",
      reporterPosition: "",
      reporterPhone: "",
      reporterEmail: "",
      coveragePlan: "",
    });

    // 加载媒体注册页面数据
    const loadMediaRegistrationData = async () => {
      try {
        const response = await subpageApi.getSubpageByKey(
          "media",
          "media-registration"
        );
        console.log("媒体注册API响应:", response);

        if (response && response.code === "200" && response.data) {
          pageData.value = {
            title: response.data.title || "媒体注册",
            subtitle:
              response.data.subtitle || "为媒体记者提供专业的展会报道服务",
          };
        }
      } catch (error) {
        console.error("加载媒体注册数据失败:", error);
      }
    };

    // 提交媒体注册
    const submitMediaRegistration = async () => {
      try {
        const payload = { ...mediaForm.value };
        const response = await mediaApi.registerMedia(payload);

        if (response && (response.code === "200" || response.code === 200)) {
          ElMessage.success("媒体注册提交成功！我们会尽快与您联系。");

          // 重置表单
          Object.keys(mediaForm.value).forEach((key) => {
            if (key === "coveragePlan") {
              mediaForm.value[key] = "";
            } else {
              mediaForm.value[key] = "";
            }
          });
        } else {
          ElMessage.error(response?.msg || "媒体注册提交失败，请重试");
        }
      } catch (error) {
        console.error("媒体注册提交失败:", error);
        ElMessage.error(error.message || "媒体注册提交失败，请重试");
      }
    };

    const loadBanner = async () => {
      try {
        const res = await subpageApi.getContentByType("carousel_media");
        if (
          res &&
          (res.code === "200" || res.code === 200) &&
          Array.isArray(res.data) &&
          res.data.length > 0
        ) {
          const firstActive =
            res.data.find((item) => item.status === "active") || res.data[0];
          bannerImage.value = firstActive.imageUrl || firstActive.image || "";
        }
      } catch (e) {
        bannerImage.value = "";
      }
    };

    onMounted(() => {
      loadMediaRegistrationData();
      loadBanner();
    });

    const setActiveTab = (tabKey) => {
      if (!tabKey) return;
      activeTab.value = tabKey;
      if (tabKey !== "media-registration") {
        window.location.href = `/${tabKey}`;
      }
    };

    return {
      activeTab,
      bannerImage,
      pageData,
      mediaForm,
      submitMediaRegistration,
      setActiveTab,
    };
  },
};
</script>

<style scoped>
.media-registration {
  min-height: 100vh;
  background: #f8f9fa;
}

.page-header {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 120px 0 80px 0;
  margin-top: 0;
  text-align: center;
  color: white;
}

.page-header.has-bg {
  height: 400px;
  position: relative;
  background: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.page-header.has-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.page-header.has-bg .container {
  position: relative;
  z-index: 1;
}

.page-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.registration-section {
  background: white;
  border-radius: 20px;
  padding: 3rem;
  margin: 2rem 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 2rem;
  color: #333;
  margin-bottom: 2rem;
  text-align: center;
}

.registration-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  /* max-width: 1000px;
  margin: 0 auto; */
}

.registration-info h3 {
  font-size: 1.8rem;
  color: var(--e-global-color-title);
  margin-bottom: 1rem;
}

.registration-info p {
  color: #666;
  line-height: 1.8;
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.media-benefits {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.benefit-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
  border-radius: 10px;
  border: 1px solid #e0e7ff;
}

.benefit-item .el-icon {
  color: var(--e-global-color-title);
  font-size: 1.2rem;
}

.benefit-item span {
  color: var(--e-global-color-title);
  font-weight: 600;
  font-size: 0.9rem;
}

.registration-form {
  background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
  border-radius: 15px;
  padding: 2rem;
  border: 1px solid #e0e7ff;
}

.media-registration-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--e-global-color-title);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #e0e7ff;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--e-global-color-selected);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.submit-btn {
  background: linear-gradient(
    135deg,
    var(--e-global-color-a3699a4) 0%,
    var(--e-global-color-5c1ca3d) 100%
  );
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.3s ease;
  margin-top: 1rem;
}

.submit-btn:hover {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .registration-section {
    padding: 2rem;
    margin: 1rem 0;
  }

  .section-title {
    font-size: 1.5rem;
  }

  .registration-content {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .media-benefits {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .form-group {
    margin-bottom: 0;
  }

  .page-title {
    font-size: 2rem;
  }

  .page-subtitle {
    font-size: 1rem;
  }
}

/* 导航菜单样式 - 参考关于我们页面 */
.nav-menu {
  background: #f8f9fa;
  padding: 20px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.about-nav {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
}

.nav-item {
  text-decoration: none;
  color: #333;
  font-size: 1.1rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease;
  border: 1px solid #eee;
  cursor: pointer;
}

.nav-item:hover {
  background-color: var(--e-global-color-selected);
  color: white;
  border-color: var(--e-global-color-selected);
}

.nav-item.active {
  background-color: var(--e-global-color-selected);
  color: white;
  border-color: var(--e-global-color-selected);
}

@media (max-width: 768px) {
  .about-nav {
    gap: 15px;
  }

  .nav-item {
    font-size: 1rem;
    padding: 8px 16px;
  }
}
</style>
